package notUseSDK

import (
	"encoding/json"
	"fmt"
	"github.com/go-resty/resty/v2"
	_ "github.com/go-resty/resty/v2"
	"time"
)

type Subscriber struct {
	Id         uint                   `json:"id"`
	CreatedAt  time.Time              `json:"created_at"`
	UpdatedAt  time.Time              `json:"updated_at"`
	Uuid       string                 `json:"uuid"`
	Email      string                 `json:"email"`
	Name       string                 `json:"name"`
	Status     string                 `json:"status"`
	Lists      []SubscriberList       `json:"lists"`
	Attributes map[string]interface{} `json:"attribs"`
}

type SubscriberList struct {
	Id                 uint      `json:"id"`
	CreatedAt          time.Time `json:"created_at"`
	UpdatedAt          time.Time `json:"updated_at"`
	Uuid               string    `json:"uuid"`
	Name               string    `json:"name"`
	Type               string    `json:"type"`
	Tags               []string  `json:"tags"`
	SubscriptionStatus string    `json:"subscription_status"`
}

func testServices() {
	username := "listmonk"
	password := "listmonk"
	baseUrl := "http://127.0.0.1:9000"
	url := baseUrl + "/api/subscribers"
	client := resty.New()
	resp, err := client.R().SetBasicAuth(username, password).EnableTrace().Get(url)
	if err != nil {
		return
	}
	fmt.Println(resp.String())

	var res map[string]map[string]interface{}
	err = json.Unmarshal(resp.Body(), &res)

	if err != nil {
		fmt.Println(err)
	}

	finalBytes, err := json.Marshal(res["data"]["results"])
	fmt.Println(string(finalBytes))

	finalRes := make([]*Subscriber, 0)
	err = json.Unmarshal(finalBytes, &finalRes)

	println(finalRes)

	//解析返回值

}
